﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class SSSequenceAction : SSAction {
    private SSAction[] sequence;
    private int cur = 0;

    public static SSSequenceAction GetSSAction() {
        SSSequenceAction action = ScriptableObject.CreateInstance<SSSequenceAction>();
        action.sequence = new SSAction[0];
        return action;
    }

    public void Init(SSAction[] sequence, int identifier = 0, ISSActionCallback callback = null) {
        base.Init(identifier, callback);
        this.sequence = (SSAction[])sequence.Clone();
    }

    public void Init(List<SSAction> sequence, int identifier = 0, ISSActionCallback callback = null) {
        Init(sequence.ToArray(), identifier, callback);
    }

    public override void Update() {
        if (cur >= sequence.Length) {
            SetOver(true);
            SendCompleteEvent();
            return;
        }
        sequence[cur].Update();
        if (sequence[cur].IsOver()) {
            ++cur;
        }
    }
}
